
import axios from "axios"
axios.defaults.baseURL = 'http://192.168.3.16:3002'
const Http = (url:any, method:any, params:any) => {
    return new Promise((resolve, reject) => {
        axios({
            url: url,
            method: method,
            ...(method === 'get' || method === 'delete' ? { params: params } : { data: params })
        }).then(res => {
            resolve(res.data)
        }).catch(err => {   
            reject(err)
})
    })
}


const Token = (url:any, method:any, params:any) => {
    return new Promise((resolve, reject) => {
        axios({
            url: url,
            method: method,
            ...(method === 'get' || method === 'delete' ? { params: params } : { data: params }),
            headers: {
                'authorization': localStorage.getItem('token')
            },
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

export { Http, Token }